<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:p="http://www.springframework.org/schema/p"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
       					   http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                           http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
                           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">

    <!-- Hibernate SessionFactory -->
    <context:annotation-config />
	<context:component-scan base-package="it.ap.sa.core, it.ap.sa.acqua.dao" />
	<aop:aspectj-autoproxy proxy-target-class="true"/><!-- evita di proxare le interfacce-->
	
    <bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean" p:dataSource-ref="myDataSource">
    	 
    	 <property name="packagesToScan" value="it.ap.sa.core.dao.model,it.ap.sa.acqua.dao.model"/>
		 
		 <property name="entityInterceptor" ref="myInterceptor"/>
		 
         <property name="hibernateProperties">
            <value>
                hibernate.dialect=${hibernate.dialect}
                hibernate.show_sql=${hibernate.show_sql}
                hibernate.format_sql=${hibernate.format_sql}
                <!-- enable second level cache and query cache -->
                hibernate.cache.region.factory_class=${hibernate.cache.region.factory_class}
         		hibernate.cache.use_second_level_cache=${hibernate.cache.use_second_level_cache}
         		hibernate.cache.use_query_cache=${hibernate.cache.use_query_cache}
         		net.sf.ehcache.configurationResourceName=${net.sf.ehcache.configurationResourceName}
         		hibernate.cache.provider_class=${hibernate.cache.provider_class}
         		temp.use_jdbc_metadata_defaults=false
            </value>
        </property>
    </bean>

    <!-- Database LOB Handling -->
    <bean id="defaultLobHandler" class="org.springframework.jdbc.support.lob.DefaultLobHandler"/>
 
    <!-- Transaction Config -->
    <bean id="transactionManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager" p:sessionFactory-ref="sessionFactory"/>

    <tx:annotation-driven transaction-manager="transactionManager"/>
    
    <!--Interceptor per gestire le proprietà utente/data inserimento/modifica -->
    <bean id="myInterceptor" class="it.ap.sa.core.dao.util.ActivityTrackerInterceptor"/>
    
</beans>